package com.pigdroid.adbsqlite.jdbc;

import java.io.IOException;
import java.sql.Array;
import java.sql.Blob;
import java.sql.CallableStatement;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.NClob;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLClientInfoException;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.SQLWarning;
import java.sql.SQLXML;
import java.sql.Savepoint;
import java.sql.Statement;
import java.sql.Struct;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Executor;

import com.pigdroid.adbsqlite.ADBSQLiteHelper;

public class ADBSQLiteConnection implements Connection {

	private String url;
	
	private ADBSQLiteHelper helper;

	private Map<String, Class<?>> typeMap = new HashMap<String, Class<?>>();

	private String catalog;
	
	public ADBSQLiteConnection(String uri, Properties props) throws SQLException {
		this.url = uri;
		try {
			helper = new ADBSQLiteHelper(props);
		} catch (IOException e) {
			throw new SQLException(e);
		}
	}

	
	public boolean isWrapperFor(Class<?> arg0) throws SQLException {
		return false;
	}

	
	public <T> T unwrap(Class<T> arg0) throws SQLException {
		return null;
	}

	
	public void abort(Executor arg0) throws SQLException {

	}

	
	public void clearWarnings() throws SQLException {

	}

	
	public void close() throws SQLException {
		try {
			helper.close();
		} catch (IOException e) {
			throw new SQLException(e);
		} catch (InterruptedException e) {
			throw new SQLException(e);
		}
	}

	
	public void commit() throws SQLException {

	}

	
	public Array createArrayOf(String arg0, Object[] arg1) throws SQLException {
		return null;
	}

	
	public Blob createBlob() throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	
	public Clob createClob() throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	
	public NClob createNClob() throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	
	public SQLXML createSQLXML() throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	
	public Statement createStatement() throws SQLException {
		return new ADBSQLiteStatement(this);
	}

	
	public Statement createStatement(int arg0, int arg1) throws SQLException {
		throw new SQLFeatureNotSupportedException();
	}

	
	public Statement createStatement(int arg0, int arg1, int arg2)
			throws SQLException {
		throw new SQLFeatureNotSupportedException();
	}

	
	public Struct createStruct(String arg0, Object[] arg1) throws SQLException {
		throw new SQLFeatureNotSupportedException();
	}

	
	public boolean getAutoCommit() throws SQLException {
		return true;
	}

	
	public String getCatalog() throws SQLException {
		return catalog;
	}

	
	public Properties getClientInfo() throws SQLException {
		return new Properties();
	}

	
	public String getClientInfo(String arg0) throws SQLException {
		return "";
	}

	
	public int getHoldability() throws SQLException {
		return ResultSet.CLOSE_CURSORS_AT_COMMIT;
	}

	
	public DatabaseMetaData getMetaData() throws SQLException {
		return new ADBSQLiteDatabaseMetadata(this);
	}

	
	public int getNetworkTimeout() throws SQLException {
		return 0;
	}

	
	public String getSchema() throws SQLException {
		return helper.getSchema();
	}

	
	public int getTransactionIsolation() throws SQLException {
		return  Connection.TRANSACTION_NONE;
	}

	
	public Map<String, Class<?>> getTypeMap() throws SQLException {
		return typeMap;
	}

	
	public SQLWarning getWarnings() throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	
	public boolean isClosed() throws SQLException {
		// TODO Auto-generated method stub
		return false;
	}

	
	public boolean isReadOnly() throws SQLException {
		// TODO Auto-generated method stub
		return false;
	}

	
	public boolean isValid(int arg0) throws SQLException {
		// TODO Auto-generated method stub
		return false;
	}

	
	public String nativeSQL(String arg0) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	
	public CallableStatement prepareCall(String arg0) throws SQLException {
		return new ADBSQLiteCallableStatement(this, arg0);
	}

	
	public CallableStatement prepareCall(String arg0, int arg1, int arg2)
			throws SQLException {
		throw new SQLFeatureNotSupportedException();
	}

	
	public CallableStatement prepareCall(String arg0, int arg1, int arg2,
			int arg3) throws SQLException {
		throw new SQLFeatureNotSupportedException();
	}

	
	public PreparedStatement prepareStatement(String arg0) throws SQLException {
		return new ADBSQLitePreparedStatement(this, arg0);
	}

	
	public PreparedStatement prepareStatement(String arg0, int arg1)
			throws SQLException {
		throw new SQLFeatureNotSupportedException();
	}

	
	public PreparedStatement prepareStatement(String arg0, int[] arg1)
			throws SQLException {
		throw new SQLFeatureNotSupportedException();
	}

	
	public PreparedStatement prepareStatement(String arg0, String[] arg1)
			throws SQLException {
		throw new SQLFeatureNotSupportedException();
	}

	
	public PreparedStatement prepareStatement(String arg0, int arg1, int arg2)
			throws SQLException {
		throw new SQLFeatureNotSupportedException();
	}

	
	public PreparedStatement prepareStatement(String arg0, int arg1, int arg2,
			int arg3) throws SQLException {
		throw new SQLFeatureNotSupportedException();
	}

	
	public void releaseSavepoint(Savepoint arg0) throws SQLException {
		throw new SQLFeatureNotSupportedException();
	}

	
	public void rollback() throws SQLException {

	}

	
	public void rollback(Savepoint arg0) throws SQLException {
		throw new SQLFeatureNotSupportedException();
	}

	
	public void setAutoCommit(boolean arg0) throws SQLException {

	}

	
	public void setCatalog(String arg0) throws SQLException {
		this.catalog = arg0;
	}

	
	public void setClientInfo(Properties arg0) throws SQLClientInfoException {
		// TODO Auto-generated method stub

	}

	
	public void setClientInfo(String arg0, String arg1)
			throws SQLClientInfoException {
		// TODO Auto-generated method stub

	}

	
	public void setHoldability(int arg0) throws SQLException {
		// TODO Auto-generated method stub

	}

	
	public void setNetworkTimeout(Executor arg0, int arg1) throws SQLException {
		// TODO Auto-generated method stub

	}

	
	public void setReadOnly(boolean arg0) throws SQLException {
		// TODO Auto-generated method stub

	}

	
	public Savepoint setSavepoint() throws SQLException {
		throw new SQLFeatureNotSupportedException();
	}

	
	public Savepoint setSavepoint(String arg0) throws SQLException {
		throw new SQLFeatureNotSupportedException();
	}

	
	public void setSchema(String arg0) throws SQLException {

	}

	
	public void setTransactionIsolation(int arg0) throws SQLException {

	}

	
	public void setTypeMap(Map<String, Class<?>> arg0) throws SQLException {
		this.typeMap.putAll(arg0);
	}

	public String getURL() {
		return url;
	}
	
	public ADBSQLiteHelper getHelper() {
		return helper;
	}

}
